﻿namespace RuoVea.CodeGen.Web.Controllers;

/// <summary>
/// SysGenProjectInfo 控制器
/// </summary>
public partial class ProjectInfoController : Controller
{
    /// <summary>
    /// 
    /// </summary>
    private readonly SysGenProjectInfoService _sysGenProjectInfoService;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="demoService"></param> 
    public ProjectInfoController(SysGenProjectInfoService sysGenProjectInfoService)
    {
        _sysGenProjectInfoService = sysGenProjectInfoService;
    }

    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("projectInfo/pages")]
    public async Task<RestfulResult<PageResult<GenProjectInfo>>> GetPagesAsync()
    {
        using var sr = new StreamReader(Request.Body);
        string dataStr = await sr.ReadToEndAsync();
        if (Request.Body.CanSeek)
            Request.Body.Position = 0;
        if (string.IsNullOrWhiteSpace(dataStr))
            throw new Exception("未提供上传数据。请在Request.Body中携带上传数据。");
        PageParam? data = JsonConvert.DeserializeObject<PageParam>(dataStr);
        data ??= new PageParam { PageNo = 1, PageSize = 10 };

        var query = await _sysGenProjectInfoService.GetPagesAsync(data);
        return query;
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <returns></returns>
    [HttpGet("projectInfo/list")]
    public async Task<RestfulResult<List<GenProjectInfo>>> GetlistAsync()
    {
        var restful = await _sysGenProjectInfoService.GetlistAsync();
        return restful;
    }

    /// <summary>
    /// 增加
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [UnitOfWork]
    [HttpPost("projectInfo/add")]
    public async Task<RestfulResult> AddAsync([FromBody] GenProjectInfo data)
    {
        var restful = await _sysGenProjectInfoService.AddAsync(data);
        return restful;
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("projectInfo/update")]
    public async Task<RestfulResult> UpdateAsync([FromBody] GenProjectInfo data)
    {
        var restful = await _sysGenProjectInfoService.UpdateAsync(data);
        return restful;
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpDelete("projectInfo/delete")]
    public async Task<RestfulResult> DeleteAsync([FromBody] EntityBaseId data)
    {
        var restful = await _sysGenProjectInfoService.DeleteAsync(data);
        return restful;
    }
}